package com.easyboot.utils.log;

import cn.hutool.core.exceptions.ExceptionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * @author yushuo
 * @className
 * @descripton TODO
 * @date 2021/2/23 9:01
 **/
public class LoggerHelper {
    private static final Logger log = LoggerFactory.getLogger(LoggerHelper.class);

    /**
     * @author yushuo
     * @description log info 写db
     * @date 11:22 2021/6/25
     * @param [title, message]
     * @return void
    **/
    public static void info(String title,String message){
         LogDto logDto=new LogDto(title,message,1,new Date(),0,0);
         LoggerQueueInstance.add(logDto);
    }
    /**
     * @author yushuo
     * @description log info 写db
     * @date 11:22 2021/6/25
     * @param [title, message]
     * @return void
     **/
    public static void info(String message){
        LogDto logDto=new LogDto("日志信息",message,1,new Date(),0,0);
        LoggerQueueInstance.add(logDto);
    }

    /**
     * @author yushuo
     * @description log info
     * @date 11:22 2021/6/25
     * @param [title, message]
     * @return void
     **/
    public static void error(String title,String message){
        LogDto logDto=new LogDto(title,message,4,new Date(),0,0);
        LoggerQueueInstance.add(logDto);
    }
    /**
     * @author yushuo
     * @description log info
     * @date 11:22 2021/6/25
     * @param [title, message]
     * @return void
     **/
    public static void error(Exception ex){
        String title= ExceptionUtil.getMessage(ex);
        String message=ExceptionUtil.stacktraceToString(ex,1000);
        LogDto logDto=new LogDto(title,message,4,new Date(),0,0);
        LoggerQueueInstance.add(logDto);
    }

    /**
     * @author yushuo
     * @description log info
     * @date 11:22 2021/6/25
     * @param [title, message]
     * @return void
     **/
    public static void error(String title,Exception ex){
        //String title= ExceptionUtil.getMessage(ex);
        String message=ExceptionUtil.stacktraceToString(ex,1000);
        LogDto logDto=new LogDto(title,message,4,new Date(),0,0);
        LoggerQueueInstance.add(logDto);
    }
    /**
     *
     * @author yushuo
     * @description 控制台输出错误信息
     * @date 15:51 2021/2/23
     * @param [msg]
     * @return void
     **/
    public static void console(String msg){
        System.err.println(msg);
    }
    /**
     *
     * @author yushuo
     * @description 异常 slf4j写file
     * @date 9:11 2021/2/23
     * @param [msg]
     * @return void
     **/
    public static  void error(String msg){
        log.error(msg);
    }

}
